<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>24岁生日倒计时</title>
    <style>
        div {
            margin: 100px auto;
            width: 300px;
            height: 300px;
        }
        
        span {
            display: inline-block;
            width: 50px;
            height: 50px;
            background-color: rgb(112, 83, 83);
            text-align: center;
            color: white;
            font-size: 18px;
            line-height: 50px;
        }
    </style>
</head>

<body>
    <div><span class="day">00</span>
        <span class="hour">00</span>
        <span class="min">00</span>
        <span class="sec">00</span>
    </div>
    <script>
        var day = document.querySelector('.day');
        var hour = document.querySelector('.hour');
        var min = document.querySelector('.min');
        var sec = document.querySelector('.sec');
        var date = new Date();
        console.log(date.getTime());
        console.log(date.valueOf());
        love(); //先调用一次防止页面刷新空白
        var getLove = setInterval(love, 1000);

        function love() {
            var date1 = +new Date();
            var date2 = +new Date('2023-6-28 00:00:00');
            console.log(date1);
            var times = date2 - date1;
            var d = parseInt(times / 1000 / 60 / 60 / 24);
            d = d < 10 ? '0' + d + '天' : d + '天';
            day.innerHTML = d;
            var h = parseInt(times / 1000 / 60 / 60 % 24);
            h = h < 10 ? '0' + h + '时' : h + '时';
            hour.innerHTML = h;
            var m = parseInt(times / 1000 / 60 % 60);
            m = m < 10 ? '0' + m + '分' : m + '分';
            min.innerHTML = m;
            var s = parseInt(times / 1000 % 60);
            s = s < 10 ? '0' + s + '秒' : s + '秒';
            sec.innerHTML = s;
            // 完成静态

        }
    </script>
</body>

</html>